<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$type=intval($_RQ['type']);
	if(!$type){
		$typetitle='箱标入库';
	}elseif($type==6){
		$typetitle='盒标入库';
	}elseif($type==1){
		$typetitle='箱标出库';
	}elseif($type==10){
		$typetitle='盒标出库';
	}elseif($type==3){
		$typetitle='箱标退货';
	}elseif($type==30){
		$typetitle='盒标退货';
	}
	$return['typetitle']=$typetitle;
	$item=array(
		'type'=>$type,
		'codes'=>array(),
		'merchid'=>$this->merchid,
		'tomid'=>'0',
	);
	$return['item']=$item;
	$return['merch']=$merch;
	$return['merchs']=pdo_getall('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','nickname','username','realname','mobile'));
	foreach($return['merchs'] as &$mv){
		$info=pdo_get('jy_yxgoodserpfw_members',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mv['id']),array('mid','mobile','cname','nickname','address'));
		$mv['nickname']=$info['nickname']?:$mv['username'];
		$mv['nickname']=$mv['nickname']?:$mv['username'];
		$mv['cname']=$info['cname'];
		$mv['address']=$info['address'];
		$mv['mobile']=$info['mobile']?:$mv['mobile'];
	}
	$return['merchs'][]=array('id'=>'0','nickname'=>'请选择下级经销商','mobile'=>'无');
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(($postdata['type']==1 || $postdata['type']==10) && !$postdata['tomid'] && !$postdata['tomobile']){
		exi('请选择下级经销商或下级经销商电话！','error');
	}
	if(!$postdata['codes']){
		exi('请扫标签！','error');
	}
	$tomid=$this->model('member')->upkulog($postdata);
	//经销商直接入库
	if($postdata['type']==1 || $postdata['type']==10){
		$postdata['type']=$postdata['type']==1?0:6;
		unset($postdata['tomid']);
		unset($postdata['tomobile']);
		$this->model('member')->upkulog($postdata,$tomid);
	}
	exi('操作成功！','','/member.index/');
}
if($_RQ['op']=='ngtomobile'){
	$tomobile=$_RQ['tomobile'];
	$check=pdo_get('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'username'=>$tomobile),array('id','fromuser'));
	$return['tomid']=$check['id'];
	if(!$return['tomid']){
		$check=pdo_get('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'mobile'=>$tomobile),array('id','fromuser'));
		$return['tomid']=$check['id'];
	}
	exi($return);
}